package com.innjia.base.enums;

import com.innjia.base.utils.StringUtils;
import com.innjia.base.utils.ValidatorUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 房间配套枚举类型
 */
public enum HardwareEnum {

	TELEVISION("television", "电视机"),
	AIR("air", "空调"),
	BED("bed", "床"),
	ICEBOX("icebox", "冰箱"),
	WASHER("washer", "洗衣机"),
	EATTABLE("eattable", "餐桌"),
	DESK("desk", "书桌"),
	CHAIR("chair", "椅子"),
	MICROWAVE("microwave", "微波炉"),
	STOVE("stove", "燃气灶"),
	HEATING("heating", "暖气"),
	RANGEHOODS("rangeHoods", "油烟机"),
	SOFA("sofa", "沙发"),
	WARDROBE("wardrobe", "衣柜"),
	AMBRY("ambry", "衣橱"),
	KITCJENANDTOILET("kitchenAndToilet", "厨卫"),
	WIFI("wifi", "wifi"),
	HEATER("heater", "热水器");

	private String code;
	private String desc;

	private HardwareEnum(String code, String desc) {
		this.code = code;
		this.desc = desc;
	}

	public static String getDescByCode(String code) {
		for(HardwareEnum e : values()) {
			if(e.getCode().equals(code)) {
				return e.getDesc();
			}
		}
		return null;
	}

	public static String getCodeByDesc(String desc) {
		for(HardwareEnum e : values()) {
			if(e.getDesc().equals(desc)) {
				return e.getCode();
			}
		}
		return "";
	}
	
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	//获得房间设备 classes  用于 APP 端渲染图标
	public static String getHardwareClass(String hardwares){
		if(ValidatorUtils.isEmpty(hardwares)){
			return "";
		}

		List<String> hardwaresList = StringUtils.string2List(hardwares);
		if(ValidatorUtils.isEmpty(hardwaresList)){
			return "";
		}
		List<String> hardwareClassList = new ArrayList<>(hardwaresList.size());
		for(String hardwareDesc : hardwaresList){
			hardwareClassList.add(getCodeByDesc(hardwareDesc));
		}

		return StringUtils.toStringBySpilt(hardwareClassList);
	}

	public static void main(String[] args){
		System.out.println(getHardwareClass("热水器,电视"));
	}
	
}
